/****************************************************************************
**
** SecondLoginConnectionGump.cpp
**
** Copyright (C) August 2014 Hotride
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
*****************************************************************************
*/
//---------------------------------------------------------------------------
#include "stdafx.h"
//---------------------------------------------------------------------------
TSecondLoginConnectionGump::TSecondLoginConnectionGump()
:m_ConnectionFailed(false), m_Connected(false), m_ErrorCode(0)
{
	UO->m_Font->GenerateA(2, m_TextureConnection, "Connecting...", 0x0386, 260.0f, TS_CENTER);

	UO->m_Font->GenerateA(2, m_TextureVerify, "Verifying Account...", 0x0386, 260.0f, TS_CENTER);


	
	UO->m_Font->GenerateA(2, m_TextureFailed[0], "Incorrect name/password.", 0x0386, 260.0f, TS_CENTER);

	UO->m_Font->GenerateA(2, m_TextureFailed[1], "Someone is already using this account.", 0x0386, 260.0f, TS_CENTER);

	UO->m_Font->GenerateA(2, m_TextureFailed[2], "Your account has been blocked.", 0x0386, 260.0f, TS_CENTER);

	UO->m_Font->GenerateA(2, m_TextureFailed[3], "Your account credentials are invalid.", 0x0386, 260.0f, TS_CENTER);

	UO->m_Font->GenerateA(2, m_TextureFailed[4], "Communication problem.", 0x0386, 260.0f, TS_CENTER);

	UO->m_Font->GenerateA(2, m_TextureFailed[5], "The IGR concurrency limit has been met.", 0x0386, 260.0f, TS_CENTER);

	UO->m_Font->GenerateA(2, m_TextureFailed[6], "The IGR time limit has been met.", 0x0386, 260.0f, TS_CENTER);

	UO->m_Font->GenerateA(2, m_TextureFailed[7], "General IGR authentication failure.", 0x0386, 260.0f, TS_CENTER);

	UO->m_Font->GenerateA(2, m_TextureFailed[8], "Couldn't connect to Ultima Online.  Please try again in a few moments.", 0x0386, 260.0f, TS_CENTER);
}
//---------------------------------------------------------------------------
TSecondLoginConnectionGump::~TSecondLoginConnectionGump()
{
	m_TextureConnection.Clear();
	m_TextureVerify.Clear();
	
	IFOR(i, 0, 9) m_TextureFailed[i].Clear();
}
//---------------------------------------------------------------------------
void TSecondLoginConnectionGump::Init()
{
	m_ConnectionFailed = false;
	m_Connected = false;
	m_ErrorCode = 0;
}
//---------------------------------------------------------------------------
int TSecondLoginConnectionGump::Render(bool mode)
{
	DWORD ticks = GetTickCount();

	if (g_LastRenderTime > ticks)
	{
		if (mode || !g_SelectGumpObjects) return 0;
	}

	if (mode)
	{
		g_LastRenderTime = ticks + g_FrameDelay;

		UO->m_GL.BeginDraw();
		
		UO->DrawGump(0x0588, 0, 0, 0, 640, 480); //Main Gump background
		UO->DrawGump(0x157C, 0, 0, 0); //Main Gump
		UO->DrawGump(0x15A0, 0, 0, 4); //Main Gump Notes
		UO->DrawGump(0x1589, 0, 555, 4); //X gump
		
		UO->DrawResizepicGump(0xA28, 142, 134, 356, 212); //Connecting field

		if (m_ConnectionFailed)
		{
			m_TextureFailed[m_ErrorCode].Draw(189, 178);

			WORD GumpID = 0x0481; //Button v
			if (g_LastObjectLeftMouseDown == 1) GumpID = 0x0483; //Button v pressed
			else if (g_LastSelectedObject == 1) GumpID = 0x0482; //Button v light
			else UO->DrawGump(GumpID, 0, 306, 304); //Button v

			UO->DrawCursor(0x2073); //Main Gump mouse cursor
		}
		else
		{
			if (!m_Connected) m_TextureConnection.Draw(189, 178);
			else m_TextureVerify.Draw(189, 178);

			UO->DrawCursor(0x2077); //Waiting mouse cursor
		}

		UO->m_GL.EndDraw();
	}
	else
	{
		g_LastSelectedObject = 0;
		g_LastObjectType = SOT_NO_OBJECT;

		if (UO->GumpPixelsInXY(0x0481, 306, 304))
		{
			g_LastSelectedObject = 1; //Button v
		}
		
		return g_LastSelectedObject;
	}
	return 0;
}
//---------------------------------------------------------------------------
void TSecondLoginConnectionGump::ParseLeftMouseDown()
{
	Render(false);

	g_DroppedLeftMouseX = g_MouseX;
	g_DroppedLeftMouseY = g_MouseY;
	g_LeftMouseDown = true;
	g_LastObjectLeftMouseDown = g_LastSelectedObject;
}
//---------------------------------------------------------------------------
void TSecondLoginConnectionGump::ParseLeftMouseUp()
{
	Render(false);

	g_LeftMouseDown = false;
	g_DroppedLeftMouseX = 0;
	g_DroppedLeftMouseY = 0;

	if (g_LastSelectedObject == 0 || g_LastSelectedObject != g_LastObjectLeftMouseDown)
	{
		g_LastObjectLeftMouseDown = 0;
		return;
	}

	if (g_LastObjectLeftMouseDown == 1) //v button
	{
		UO->InitGump(GS_MAIN);
	}

	g_LastObjectLeftMouseDown = 0;
}
//---------------------------------------------------------------------------
void TSecondLoginConnectionGump::ParseRightMouseDown()
{
}
//---------------------------------------------------------------------------
void TSecondLoginConnectionGump::ParseRightMouseUp()
{
}
//---------------------------------------------------------------------------
bool TSecondLoginConnectionGump::ParseLeftMouseDoubleClick()
{
	return false;
}
//---------------------------------------------------------------------------
bool TSecondLoginConnectionGump::ParseRightMouseDoubleClick()
{
	return false;
}
//---------------------------------------------------------------------------
void TSecondLoginConnectionGump::ParseMouseWheel(MOUSE_WHEEL_STATE state)
{
}
//---------------------------------------------------------------------------
void TSecondLoginConnectionGump::ParseCharPress(WPARAM wparam, LPARAM lparam)
{
}
//---------------------------------------------------------------------------
void TSecondLoginConnectionGump::ParseKeyPress(WPARAM wparam, LPARAM lparam)
{
	switch (wparam)
	{
		case VK_RETURN:
		{
			if (m_ConnectionFailed) UO->InitGump(GS_MAIN);
			return;
		}
		default: break;
	}
}
//---------------------------------------------------------------------------